package com.guang.interupt.park;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @Description 测试LockSupport.park();，只会park住中断标记为false的，不会打断中断标记为true的
 * @Author liguang
 * @Date 2023/06/20/17:51
 */
public class ParkInteruptTestThree {
    private static Logger logger = LoggerFactory.getLogger(ParkInteruptTestThree.class);


    public static void main(String[] args) throws InterruptedException {
        testParkOne();
    }

    private static void testParkOne() throws InterruptedException {
        Thread threadA = new Thread(() -> {
            // park住的线程是因为中断唤醒的，那么将无法再次park住
            logger.info("当前线程正在执行........");
            LockSupport.park();
            Thread.interrupted();
            logger.info("当前线程是因为中断而被唤醒的");
            LockSupport.park();
            Thread.interrupted();
            logger.info("当前线程是因为再次中断而被唤醒的");
        }, "threadA");

        threadA.start();
        TimeUnit.SECONDS.sleep(2);
        threadA.interrupt();
    }
}
